<?php

namespace app\model\tree;

use app\BaseModel;
use app\model\UserModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;

/**
 * 心灵智慧树-果实
 */
class TreeFruitModel extends BaseModel
{
    protected $name = 'tree_fruit';

    /**
     * 用户
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(UserModel::class,'uid')->bind([
            'user_name' => 'name',
            'avatar'
        ]);
    }


    /**
     * 智慧树个人信息配置
     * @return BelongsTo
     */
    public function treeUserInfo(): BelongsTo
    {
        return $this->belongsTo(TreeUserInfoModel::class,'uid','uid')->bind([
            'nickname',
            'nickname_avatar' => 'avatar',
        ]);
    }

    /**
     * 评论
     * @return HasMany
     */
    public function fruitComment(): HasMany
    {
        return $this->hasMany(TreeFruitCommentModel::class,'fruit_id');
    }

    /**
     * 图片
     * @return HasMany
     */
    public function fruitImg(): HasMany
    {
        return $this->hasMany(TreeFruitImgModel::class,'fruit_id');
    }


}